import utils.TreeNode;

import java.util.List;

/**
 * @author ZCR
 * @create 2025/9/5 00:27
 */
public class Solution112 {
    public boolean isEqual= false;
    public boolean hasPathSum(TreeNode root, int targetSum) {
        if (root == null) {
            return false;
        }
        backtrack(root, targetSum);
        return isEqual;
    }
    public void backtrack(TreeNode root,int sum) {
        sum -= root.val;
        if(root.left == null && root.right == null && sum  ==0) {
            isEqual = true;
        }
        if(root.left != null) {
            backtrack(root.left,sum);
        }
        if(root.right != null) {
            backtrack(root.right,sum);
        }
    }

}
